from enum import IntEnum

from items.base import BaseInsertItem, BaseModel


class TaskStatus(IntEnum):
    success: int = 0
    ready_to_run: int = 1
    running: int = 2
    failed: int = 3


class RunningModelItem(BaseModel):
    model_name: str
    model_kwargs: dict


class FailedModelItem(RunningModelItem):
    message: str


class TaskItem(BaseInsertItem):
    """
    exe_models example
    >>> exe_models = {
    >>>     "shipping_inbounds": [ # 要爬虫运行的模块名称，与运行参数的数组，运行次数是数组的长度,没有参数直接用 {}
    >>>         {"id": "1283790"}, # 带一个ID参数执行
    >>>         {"id": "1283791"},
    >>>         {}, # 不带参数执行
    >>>     ],
    >>>     "other_model": [
    >>>         {"id": "55591984"},
    >>>         {"id": "55591983"},
    >>>     ]
    >>> }
    failed_models example
    >>> failed_models = [
    >>>     {
    >>>         "model_name":"shipping_inbounds",
    >>>         "model_kwargs":{"id": "1283791"},
    >>>         "message":"",
    >>>     }
    >>> ]
}
    """
    platform: str
    browser_id: str
    exe_models: dict[str, list[dict]]  # 需要执行的模块
    # models_kwargs: dict  # 执行模块的参数
    module_reference: str  # 模块映射路径
    retry_times: int
    status: TaskStatus
    message: str
    failed_models: dict[str, FailedModelItem] = {}  # 存储在运行失败的模块
    running_models: dict[str, RunningModelItem] = {}  # 存储在运行中的模块


if __name__ == '__main__':
    print(TaskItem(
        platform="",
        browser_id="",
        exe_models={
            "shipping_inbounds": [  # 要爬虫运行的模块名称，与运行参数的数组，运行次数是数组的长度,没有参数直接用 {}
                {"id": "1283790"},  # 带一个ID参数执行
                {"id": "1283791"},
                {},  # 不带参数执行
            ],
            "other_model": [
                {"id": "55591984"},
                {"id": "55591983"},
            ]
        },
        module_reference="",
        retry_times=0,
        status=TaskStatus.ready_to_run,
        message="",
    ).json())
